<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="images/reset.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<link href="images/system.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<link href="images/table_form.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<script src="{yun:}$config.sy_weburl{/yun}/js/jquery-1.8.0.min.js?v={yun:}$config.cachecode{/yun}"></script>
<script src="js/admin_public.js?v={yun:}$config.cachecode{/yun}" type="text/javascript"></script>
<link href="{yun:}$config.sy_weburl{/yun}/js/layui/css/layui.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<script src="{yun:}$config.sy_weburl{/yun}/js/layui/layui.js?v={yun:}$config.cachecode{/yun}"></script>
<script src="{yun:}$config.sy_weburl{/yun}/js/layui/phpyun_layer.js?v={yun:}$config.cachecode{/yun}"></script>
<title>后台管理</title>
</head>
<body class="body_ifm">
<div class="infoboxp" style="position:relative;">

<div id="subboxdiv" style="width:100%;height:100%;display:none;position:absolute; z-index:10000"></div>
<div class="main_tag" >
<div class="tabs_info ">
<ul>
	<li class="on">基本设置</li>
    <li>同步记录</li>
</ul>
</div>
<div class="admin_new_tip">
<a href="javascript:;" class="admin_new_tip_close"></a>
<a href="javascript:;" class="admin_new_tip_open" style="display:none;"></a>
<div class="admin_new_tit"><i class="admin_new_tit_icon"></i>操作提示</div>
<div class="admin_new_tip_list_cont">
<div class="admin_new_tip_list">该页面展示了网站的导航信息，可对导航进行设置操作。</div>
</div>
</div>

<div class="tag_box" style="margin-top:10px;">
<div>
<input type="hidden" name="pytoken" id='pytoken' value="{yun:}$pytoken{/yun}">
<table width="100%" class="table_form">
<tr class="admin_table_trbg">
  <th width="160" bgcolor="#f0f6fb"><span class="admin_bold">参数说明</span></th>
          <td bgcolor="#f0f6fb"><span class="admin_bold">参数值</span></td>
</tr>
<tr >
<th width="160">CRM同步标识： </th>
<td><input class="input-text  tips_class" type="text" name="crmname" id="crmname" value="{yun:}$config.crmname{/yun}" size="40" maxlength="255"/>
<span class="admin_web_tip">如：PHP云人才招聘系统，请与CRM系统设置一致</span></td>
</tr>
<tr class="admin_table_trbg">
		<th width="160">CRM同步KEY：</th>
		<td><input class="input-text tips_class" type="text" name="crmkey" id="crmkey" value="{yun:}if $config.crmkey{/yun}{yun:}$config.crmkey{/yun}{yun:}else{/yun}{yun:}$config.crmkey{/yun}{yun:}/if{/yun}" size="40" maxlength="255"/>
        <span class="admin_web_tip">如：uhjll12jhhdddmmm2,请与CRM系统设置一致</span></td>
	</tr>
	 <tr>
<th width="160">订单类别ID： </th>
<td><input class="input-text  tips_class" type="text" name="crmpronid" id="crmpronid" value="{yun:}$config.crmpronid{/yun}" size="40" maxlength="255"/>
<span class="admin_web_tip">请与CRM系统产品类别ID一致,多个以半角逗号隔开。</span></td>
</tr>
<tr class="admin_table_trbg">
	    <th>&nbsp;</th>
          <td align="left"><input class="layui-btn layui-btn-normal" id="config" type="button" name="config" value="提交">&nbsp;&nbsp;<input class="layui-btn layui-btn-normal" type="reset" value="重置"/></td>
	</tr>
</table>
</div>

<div class="hiddendiv">
    <table width="100%" class="table_form">
    <tr class="admin_table_trbg">
     <th width="160" bgcolor="#f0f6fb"><span class="admin_bold">参数说明</span></th>
          <td bgcolor="#f0f6fb"><span class="admin_bold">参数值</span></td>
</tr>
     <tr>
		<th width="160">可同步有效用户数：</th>
		<td>{yun:}$usercount{/yun}</td>
		<input type="hidden" id="usercount" value="{yun:}$usercount{/yun}">
	</tr>
	<tr class="admin_table_trbg">
		<th width="160">CRM同步基数：</th>
		<td><input class="input-text tips_class" type="text"  id="crmlimit" value="1000" size="40" maxlength="255"/><span class="admin_web_tip">每次同步用户数量，建议设置为1000-10000之间，不宜过大</span></td>
	</tr>

        <tr>
             <th>&nbsp;</th>
          <td align="left">
            <input class="admin_button admin_buttonpz" id="sync" type="button" name="sync" value="开始同步" />&nbsp;&nbsp;
            <input class="admin_button admin_buttonpz" type="reset" value="重置" /></td>
        </tr>
    </table>
</div>

</div>
</div>
<script>
var $switchtag = $("div.main_tag ul li");
$switchtag.click(function(){
	$(this).addClass("on").siblings().removeClass("on");
	var index = $switchtag.index(this);
	$("div.tag_box > div")
		.eq(index).show()
		.siblings().hide();
});

$(".tips_class").hover(function(){

	var msg_id=$(this).attr('id');
	var msg=$('#'+msg_id+' + font').html();
	if($.trim(msg)!=''){
		layer.tips(msg, this, {
		guide: 1,
		style: ['background-color:#5EA7DC; color:#fff;top:-7px', '#5EA7DC']
		});
		$(".xubox_layer").addClass("xubox_tips_border");
	}
},function(){
	var msg_id=$(this).attr('id');
	var msg=$('#'+msg_id+' + font').html();
	if($.trim(msg)!=''){
		layer.closeAll('tips');
	}
});

$(function(){
	$("#config").click(function(){
		$.post("index.php?m=config&c=save",{
			config : $("#config").val(),
			crmname : $("#crmname").val(),
			crmpronid : $("#crmpronid").val(),
			pytoken : $("#pytoken").val(),
			crmkey : $("#crmkey").val()
		},function(data,textStatus){
			config_msg(data); return false;
		});
	});
	$("#sync").click(function(){
		var ii = parent.layer.load('数据传输中,请不要关闭或刷新页面！',0);
		var count = '{yun:}$usercount{/yun}';
		var limit = $('#crmlimit').val();
		psotcrm(ii,count,limit);
	});
});

function psotcrm(ii,count,limit){
	$.post("index.php?m=crmsync&c=sync",{
			count : count,
			pytoken : $("#pytoken").val(),
			limit : limit
		},function(data){
			var info = eval('('+data+')');
			if(info['state']=='0'){
				parent.layer.closeAll();
				parent.layer.alert('数据同步成功！', 9);
				window.location.href='index.php?m=crmsync';
			}else if(info['state']=='1'){
				parent.layer.closeAll();
				var allcount = $('#usercount').val();
				var hascount = parseInt(allcount)-parseInt(info['count']);
				var ii = parent.layer.load('数据已传输 '+hascount+'条，请耐心等待！',0);
				psotcrm(ii,info['count'],limit);
			}else{
				parent.layer.closeAll();
				parent.layer.alert('数据同步失败', 8);
				window.location.href='index.php?m=crmsync';
			}
		});
}
</script>
</div>
</body>
</html>